import { createStore } from 'vuex';
import login from "./login/login"
import system from './system/system'
import dashboard from './analysis/dashboard'
import {getPageListData}  from '@/service/main/system/system'
// 初始化本地存储
export function setupStore(){
  store.dispatch('login/loadLocalLogin')
  store.dispatch('getInitialDataAction')
}
const store=createStore({
  state(){
   return{
     entireDepartment:[],
     entireRole:[],
     entireMenu:[]
   }
  },
  mutations: {
    changeEntireDepartment(state:any,list){
      state.entireDepartment=list
    },
    changeEntireRole(state:any,list){
      state.entireRole=list
    },
    changeEntireMenu(state,list){
        state.entireMenu=list
     
        
    }  

  },
  actions: {
   async getInitialDataAction({ commit }){
    //  请求角色部门数据
    const departmaentResult=await getPageListData('/department/list',{
      offset:0,
      size:1000
    })
    const { list : departmentList}=departmaentResult.data


    const roleResult=await getPageListData('/role/list',{
      offset:0,
      size:1000
    })
    const { list : roleList}=roleResult.data

    const menuResult=await getPageListData('/menu/list',{})
    const {list :menuList}=menuResult.data
    // console.log(menuList);
    
        // 保存数据
        commit('changeEntireDepartment',departmentList)
        commit('changeEntireRole',roleList)
        commit('changeEntireMenu',menuList)
    }
     
  },
  modules: {
    login,
    system,
    dashboard
  }
  
})
export default store

